package thread;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

public class SyncApiDemo2 {
    public static void main(String[] args) {
      //  List<Integer>list=new ArrayList<>();
        Collection<Integer> c= Collections.synchronizedCollection(new ArrayList<>());
        Thread t1=new Thread(){
            public void run(){
                for (int i=0;i<1000;i++){
                   c.add(i);
                }
            }
        };
        Thread t2=new Thread(){
            public void run(){
                for (int i=1000;i<2000;i++){
                   c.add(i);
                }
            }
        };
        t1.start();
        t2.start();
    }
}
